package com.haixee.parkdemo.logistics.controller;

import com.haixee.parkdemo.common.response.ResResult;
import com.haixee.parkdemo.common.response.ResUtil;
import com.haixee.parkdemo.data_acl.annotation.DataAclSetting;
import com.haixee.parkdemo.logistics.entity.vo.ContentVO;
import com.haixee.parkdemo.logistics.model.Content;
import com.haixee.parkdemo.logistics.service.impl.ContentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    @PostMapping("/update")
    public ResResult update(@RequestBody Content content) {
        contentService.updateContent(content);
        return ResUtil.success();
    }

    @GetMapping("/list")
    @DataAclSetting(voClass = ContentVO.class)
    public ResResult list() {

        List<Content> contents = contentService.select();
        List<ContentVO> contentVOS = new ArrayList<>(contents.size());

        for (Content content : contents) {
            ContentVO contentVO = new ContentVO();
            BeanUtils.copyProperties(content, contentVO);
            contentVO.setOptJob(content.getOptOrgJob());
            contentVOS.add(contentVO);
        }

        return ResUtil.success(contentVOS);
    }
}
